/*
 * 初始化Dom7 
 */
var $$ = Dom7;
/*
 * 
 * 通用JS
 * 
 */
(function(w, $$) {
	/**手机APP顶部留出状态栏***/
	var immersed = 0;
	var ms = (/Html5Plus\/.+\s\(.*(Immersed\/(\d+\.?\d*).*)\)/gi).exec(navigator.userAgent);
	if(ms && ms.length >= 3) {
		immersed = parseFloat(ms[2]);
	};
	w.immersed = immersed;
	if(!immersed) {
		return;
	};
	$$("#app").css({
		"paddingTop": (+immersed) / 10 + "rem",
	});
	/***数据处理***/
	w.dataHandle = (response) => {
		var _rows = JSON.parse(response.rows);
		var data = [];
		for(var i in _rows) {
			var _arr = {};
			for(var j in response.columns) {
				_arr[response['columns'][j]['显示名']] = _rows[i][j];
			};
			data.push(_arr);
		};
		return data;
	};
	/***添加加载图片***/
	w.addLoading = () => {
		$$("body").append("<div class='loadings' style='position:fixed;left:0px;right:0px;top:50px;bottom:0px;z-index:9999;'><img src='../i/loading.gif' style='top:50%;left:50%;position:absolute;transform:translate(-50% -50%);'></div>");
	};
	/***存储资产数据数据库***/
	w.inventoryAssetData = openDatabase("inventoryAssetData", "1.0", "盘点总资产数据", 50 * 1024 * 1024);

	w.onBackKeyDown = function() {
		var currentView = app.view[0].router;
		if(currentView.history.length > 1) {
			currentView.router.back({}); //非首页返回上一级  
		} else {
			//			navigator.app.exitApp();//首页点返回键退出应用  
		}
	};

})(window, Dom7);

/*
 * 
 * 初始化framework7
 * 
 */

var app = new Framework7({
	// App root element
	root: '#app',
	// App Name
	name: 'My App',
	// App id
	id: 'com.myapp.test',
	// Enable swipe panel
	panel: {
		swipe: 'left',
	},
	// Add default routes
	routes: routesData,
	statusbar: {
		overlay: false
	},
	dialog: {
		title: "固定资产",
		buttonOk: '确定',
		buttonCancel: "取消"
	}
});
//document.addEventListener('backbutton', onBackKeyDown, false);

window.db = '';
window.appIndexedDb = indexedDB.open("inventoryAssetData", 1);
appIndexedDb.onsuccess = function(e) {
	db = e.target.result;
//	console.log('连接数据库成功');
};
appIndexedDb.onerror = function() {
//	console.log('连接数据库失败');
};
appIndexedDb.onupgradeneeded = function(e) {
	db = e.target.result;
	if(!db.objectStoreNames.contains('AssetInfo')) {
		var store = db.createObjectStore('AssetInfo', {
			keyPath: 'Id',
			autoIncrement: true
		});
	};
};


document.addEventListener("trimmemory", onAppTrimMemory, false);
function onAppTrimMemory(){
	console.log("Trim Memory!"); 
}